package com.hncc.pms.controller;

import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.hncc.pms.domain.PmsPatient;
import com.hncc.pms.service.IPmsPatientService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;

/**
 * 病人基本信息Controller
 * 
 * @author ruoyi
 * @date 2020-09-04
 */
@RestController
@RequestMapping("/pms/patient")
@Api(tags = "病人基本信息接口")
public class PmsPatientController extends BaseController
{
    @Resource
    private IPmsPatientService pmsPatientService;

    /**
     * 查询病人基本信息列表
     */
    @ApiOperation(value = "条件分页查询病人基本信息",httpMethod = "GET")
    @PreAuthorize("@ss.hasPermi('pms:patient:list')")
    @GetMapping("/list")
    public TableDataInfo list(PmsPatient pmsPatient)
    {
        startPage();
        List<PmsPatient> list = pmsPatientService.selectPmsPatientList(pmsPatient);
        return getDataTable(list);
    }


    /**
     * 导出病人基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('pms:patient:export')")
    @Log(title = "病人基本信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PmsPatient pmsPatient)
    {
        List<PmsPatient> list = pmsPatientService.selectPmsPatientList(pmsPatient);
        ExcelUtil<PmsPatient> util = new ExcelUtil<PmsPatient>(PmsPatient.class);
        return util.exportExcel(list, "patient");
    }

    /**
     * 获取病人基本信息详细信息
     */
    @ApiOperation(value = "根据id获取病人基本信息详细信息",httpMethod = "GET",
            notes = "根据id查询病人基本信息")
    @ApiImplicitParam(paramType = "path",name = "id",value = "病人基本信息id",dataType = "Long",required = true)
    @PreAuthorize("@ss.hasPermi('pms:patient:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(pmsPatientService.selectPmsPatientById(id));
    }

    /**
     * 根据身份证查询病人基本信息
     * @param identNo
     * @return
     */
    @GetMapping(value = "/getByIdent/{identNo}")
    public AjaxResult getInfoByIdent(@PathVariable String identNo){
        if (pmsPatientService.selectPmsPatientByIdentNo(identNo)!=null){
            return AjaxResult.success(pmsPatientService.selectPmsPatientByIdentNo(identNo));
        }
        return AjaxResult.error("无病人信息",null);
    }

    /**
     * 新增病人基本信息
     */
    @ApiOperation(value = "新增",httpMethod = "POST", notes = "新增病人基本信息")
    @ApiImplicitParam(name = "pmsPatient", value = "新增病人基本信息", dataType = "PmsPatient")
    @PreAuthorize("@ss.hasPermi('pms:patient:add')")
    @Log(title = "病人基本信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PmsPatient pmsPatient)
    {
        if (pmsPatientService.insertPmsPatient(pmsPatient)>0){
            return AjaxResult.success(pmsPatient.getId());
        }
        return AjaxResult.success(null);
    }

    /**
     * 修改病人基本信息
     */
    @ApiOperation(value = "修改", httpMethod = "PUT", notes = "修改病人基本信息")
    @ApiImplicitParam(name = "pmsPatient", value = "修改病人基本信息", dataType = "PmsPatient")
    @PreAuthorize("@ss.hasPermi('pms:patient:edit')")
    @Log(title = "病人基本信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PmsPatient pmsPatient)
    {
        return toAjax(pmsPatientService.updatePmsPatient(pmsPatient));
    }

    /**
     * 删除病人基本信息
     */
    @ApiOperation(value = "批量删除", httpMethod = "DELETE", notes = "根据ids删除病人基本信息")
    @ApiImplicitParam(paramType = "path",name = "ids",value = "病人基本信息id",dataType = "Long[]",required = true)
    @PreAuthorize("@ss.hasPermi('pms:patient:remove')")
    @Log(title = "病人基本信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pmsPatientService.deletePmsPatientByIds(ids));
    }
}
